import store from "../store";


export function formatDate(date) {
    if (!date) return '';
    const d = new Date(date);
    const year = d.getFullYear();
    const month = String(d.getMonth() + 1).padStart(2, '0');
    const day = String(d.getDate()).padStart(2, '0');
    const hours = String(d.getHours()).padStart(2, '0');
    const minutes = String(d.getMinutes()).padStart(2, '0');
    const seconds = String(d.getSeconds()).padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export function validPermision(selectMenu=0){
    console.log('validPermision','start')
    selectMenu = 0
    var menus = document.getElementsByClassName('menu_item')
    var userInfoStore = store.state.userInfoStore
    console.log('menus',menus,'用户信息store', userInfoStore)
    for (let indx = 0; indx < menus.length; indx++) {
        const element = menus[indx];
        if(!userInfoStore['optPermission'].includes(element.id)){
            element.style.display = 'none'
          }else{

            if(selectMenu==0){
              selectMenu = indx+1
            }
            element.style.display = 'block'
          }
    }
    var tmenus = document.getElementsByClassName('tab_item')


    for (let indx = 0; indx < tmenus.length; indx++) {
        const element = tmenus[indx];
        if (element.id!=null&&element.id!=''){
            if(!userInfoStore['optPermission'].includes(element.id)){
                element.style.display = 'none'
              }else{
                element.style.display = 'block'
              }
        }

    }

}

export function formatCurrentTime() {
    const now = new Date();
    const year = now.getFullYear();
    const month = (now.getMonth() + 1).toString().padStart(2, '0');
    const day = now.getDate().toString().padStart(2, '0');
    const hours = now.getHours().toString().padStart(2, '0');
    const minutes = now.getMinutes().toString().padStart(2, '0');
    const seconds = now.getSeconds().toString().padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  }

export function formatCurrentShiftTime() {
  const now = new Date();
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  return `${hours}:${minutes}:${seconds}`;
}
